# import tkinter as tk
# import time
# #定义窗口
# window = tk.Tk()
# window.title("北京时间")
# window.geometry("400x200")
# window.iconbitmap('D:\实例图片.jpg')
# #获取时间的函数
# def get_time():
#     time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
#     label.config(text=time_str)
#     window.after(1000, get_time)
# #创建标签
# label = tk.Label(window, font=("Arial", 40), fg="red", bg="yellow")
# label.pack()
# #调用函数获取时间
# get_time()
# window.mainloop()

# import tkinter as tk
# win=tk.Tk()
# win.title("colov11")
# win.geometry("400x200")
# win.iconbitmap('D:/实例图片.jpg')
# label=tk.Label(win,text="colov11",font=("宋体",40),bg="#7CCD7C",
#                #设置标签内容区大小
#                width=20,height=5,
#                #设置填充区距离、边框距离和凹陷式
#                padx=10,pady=15,bd=10,relief="sunken")
# label.pack()
# win.mainloop()

# import tkinter as tk
# from tkinter import messagebox
# win=tk.Tk()
# win.title("colov11")
# win.geometry("400x200+300+200")
# #当按钮被点击时执行click_button()函数
# def click_button():
#     messagebox.showinfo("温馨提示","你点错了哦！")
# #创建按钮
# button=tk.Button(win,text="点击前往",font=("Arial",20),bg="white",width=20,height=5,command=click_button)
# button.pack()
# win.mainloop()

# import tkinter as tk
# from tkinter import messagebox
# win=tk.Tk()
# win.title("colov11")
# win.iconbitmap
# win.geometry("400x200+200+200")
# win.resizable(0,0)
# #将两个标签分别放在第一行、第二行
# tk.Label(win,text="账号:  ").grid(row=0)
# tk.Label(win,text="密码:  ").grid(row=1)
# label1=tk.Entry(win)
# label1.grid(row=0,column=1,padx=10,pady=5)
# label2=tk.Entry(win,show='$')
# label2.grid(row=1,column=1,padx=10,pady=5)
# #编写一个简单的回调函数
# def login():
#     messagebox.showinfo("登录成功","欢迎你的到来")
# #使用grid()的函数来布局，并控制按钮的位置
# button=tk.Button(win,text="登录",width=10,command=login)
# button.grid(row=3,column=0,padx=10,pady=5)
# button=tk.Button(win,text="取消",width=10,command=win.quit)
# button.grid(row=3,column=1,padx=10,pady=5)
# win.mainloop()

# import tkinter as tk
# from tkinter import messagebox

# win = tk.Tk()
# # 设置主窗口
# win.title("colov11")
# win.iconbitmap("D:/实例图片.jpg")
# win.geometry("400x200+200+200")
# win.resizable(0, 0)

# # 创建验证函数，要求账号必须为数字，密码必须包含大小写字母和特殊字符，长度大于等于8
# def check_account(account):
#     if account.isdigit():
#         return True
#     else:
#         return False

# def check_password(password):
#     if (len(password) >= 8 and 
#         any(char.isdigit() for char in password) and 
#         any(char.isupper() for char in password) and 
#         any(char.islower() for char in password) and 
#         any(char in "!@#$%^&*()" for char in password)):
#         return True
#     else:
#         return False

# # 新建文本标签
# tk.Label(win, text="账号:  ").grid(row=0)
# tk.Label(win, text="密码:  ").grid(row=1)

# # 创建动态字符串
# account_var = tk.StringVar()
# password_var = tk.StringVar()

# # 创建输入框（移除实时验证，只保留基本输入功能）
# account_entry = tk.Entry(win, textvariable=account_var)
# password_entry = tk.Entry(win, textvariable=password_var, show='*')

# # 对控件进行布局管理，放在文本标签的后面
# account_entry.grid(row=0, column=1)
# password_entry.grid(row=1, column=1)

# # 编写登录函数
# def login():
#     account = account_var.get()
#     password = password_var.get()
    
#     account_valid = check_account(account)
#     password_valid = check_password(password)
    
#     if account_valid and password_valid:
#         messagebox.showinfo("登录成功", "欢迎你的到来")
#     else:
#         if not account_valid and not password_valid:
#             messagebox.showerror("登录失败", "账号必须为数字\n密码必须包含大小写字母、数字和特殊字符(!@#$%^&*())，长度至少8位")
#         elif not account_valid:
#             messagebox.showerror("登录失败", "账号必须为数字")
#         else:
#             messagebox.showerror("登录失败", "密码必须包含大小写字母、数字和特殊字符(!@#$%^&*())，长度至少8位")

# # 添加登录和取消按钮
# login_button = tk.Button(win, text="登录", width=10, command=login)
# login_button.grid(row=3, column=0, padx=10, pady=5)
# cancel_button = tk.Button(win, text="取消", width=10, command=win.quit)
# cancel_button.grid(row=3, column=1, padx=10, pady=5)

# win.mainloop()


# import tkinter as tk
# root = tk.Tk()
# root.title("colov11")
# root.geometry("400x200+200+200")
# root.iconbitmap("D:/实例图片.jpg")
# #如果是数字使用from和to参数，范围0-20，并且与2步长递增
# w=tk.Spinbox(root,from_=0,to=20,increment=2,width=15,bg='#FF00FF')
# w.pack()
# root.mainloop()

# import tkinter as tk
# root = tk.Tk()
# root.title("colov11")
# root.geometry("400x200+200+200")
# root.iconbitmap("D:/实例图片.jpg")
# #使用values参数以元组的形式进行传参
# strings=tk.Spinbox(root,values=('Python','java','C语言','PHP'),width=15,bg='#FF00FF')
# strings.pack()
# root.mainloop()


# from tkinter import *
# win = Tk()
# win.title("colov11")
# win.geometry("400x200+200+200")
# win.iconbitmap("D:/实例图片.jpg")
# # 创建Text控件并调整尺寸
# text = Text(win, width=40, height=8, undo=True, bg="white", fg="black")
# text.grid(row=0, column=0, padx=10, pady=10, columnspan=2)
# # 插入初始文本
# text.insert(INSERT, "colov11")
# # 创建撤销和恢复按钮
# Button(win, text="撤销", command=text.edit_undo).grid(row=1, column=0, sticky='w', padx=10, pady=5)
# Button(win, text="恢复", command=text.edit_redo).grid(row=1, column=1, sticky='e', padx=10, pady=5)
# win.mainloop()


# from tkinter import *
# import tkinter.messagebox
# win = Tk()
# win.configure(bg="#87CEEB")
# win.title("colov11")
# win.geometry("400x200+200+200")
# win.iconbitmap("D:/实例图片.jpg")
# #绑定一个执行函数，当点击菜单项的时候会显示一个消息对话框
# def show_message():
#     tkinter.messagebox.showinfo("主菜单栏", "你正在使用主菜单")
# #创建一个主目录菜单
# main_menu = Menu(win)
# #新增命令菜单项，使用add_command()方法实现
# main_menu.add_command(label="文件", command=show_message)
# main_menu.add_command(label="编辑", command=show_message)
# main_menu.add_command(label="格式", command=show_message)
# main_menu.add_command(label="查看", command=show_message)
# main_menu.add_command(label="帮助", command=show_message)
# win.config(menu=main_menu)
# win.mainloop()


# import tkinter as tk
# win = tk.Tk()
# win.config(bg="#87CEEB")
# win.title("colov11")
# win.geometry("400x200+200+200")
# win.iconbitmap("D:/实例图片.jpg")
# def func():
#     print("你通过弹出菜单执行了命令")
# main_menu = tk.Menu(win)
# main_menu.add_command(label="新建", command=func)
# main_menu.add_command(label="复制", command=func)
# main_menu.add_command(label="粘贴", command=func)
# main_menu.add_command(label="剪切", command=func)
# #定义事件函数
# def popup(event):
#     main_menu.post(event.x_root, event.y_root)
# win.bind("<Button-3>", popup)
# win.mainloop()

# import tkinter as tk
# from tkinter import filedialog
# import tkinter.messagebox
# win = tk.Tk()
# win.config(bg="#87CEEB")
# win.title("colov11")
# win.geometry("400x200+200+200")
# win.iconbitmap("D:/实例图片.jpg")
# def menuCommand():
#     tkinter.messagebox.showinfo("下拉菜单", "你正在使用下拉菜单功能")
# #添加打开文件的方法
# text_area = tk.Text(win, width=40, height=10)
# text_area.pack(padx=10, pady=10)
# status_label = tk.Label(win, text="欢迎使用 colov11", bd=1, relief=tk.SUNKEN, anchor=tk.W)
# status_label.pack(side=tk.BOTTOM, fill=tk.X)
# def open_file():
#     # 打开文件选择对话框，只允许选择文本文件
#     file_path = filedialog.askopenfilename(
#         title="选择文件",
#         filetypes=[("文本文件", "*.txt"), ("所有文件", "*.*")]  # 可筛选文件类型
#     )
    
#     if not file_path:  # 如果用户取消选择，直接返回
#         return
    
#     try:
#         # 读取文件内容
#         with open(file_path, 'r', encoding='utf-8') as file:
#             content = file.read()
        
#         # 清空文本框并显示内容
#         text_area.delete(1.0, tk.END)
#         text_area.insert(tk.END, content)
        
#         # 显示打开成功的信息
#         status_label.config(text=f"已打开文件: {file_path}")
        
#     except Exception as e:
#         # 处理打开失败的情况（如文件损坏、无权限等）
#         tkinter.messagebox.showerror("错误", f"无法打开文件：{str(e)}")

# #创建一个主目录菜单
# mainmenu = tk.Menu(win)
# filemenu = tk.Menu(mainmenu, tearoff=False)

# filemenu.add_command(label="新建", command=menuCommand,accelerator="Ctrl+N")
# filemenu.add_command(label="打开", command=open_file,accelerator="Ctrl+O")
# filemenu.add_command(label="保存", command=menuCommand,accelerator="Ctrl+S")
# #添加一条分割线
# filemenu.add_separator()
# filemenu.add_command(label="退出", command=win.quit)
# #在主目录菜单中添加filemenu，并通过menu参数与下拉菜单绑定
# mainmenu.add_cascade(label="文件", menu=filemenu)
# #将主菜单添加到窗口中
# win.config(menu=mainmenu)
# #绑定键盘事件，按下键盘上相应的键时都会出发执行函数
# win.bind("<Control-n>", menuCommand)
# win.bind("<Control-o>", menuCommand)
# win.bind("<Control-s>", menuCommand)
# win.bind("<Control-N>", menuCommand)
# win.bind("<Control-O>", menuCommand)
# win.bind("<Control-S>", menuCommand)


# win.mainloop()


# import tkinter as tk
# win=tk.Tk()
# win.title("colov11")
# win.geometry("400x200+200+200")
# win.iconbitmap("D:/实例图片.jpg")
# frame1=tk.Frame(win)
# frame1.pack()
# frame_left=tk.Frame(frame1)
# tk.Label(frame_left,text="左侧标签1",bg="green",width=10,height=5).grid(row=0,column=0)
# tk.Label(frame_left,text="左侧标签2",bg="yellow",width=10,height=5).grid(row=1,column=1)
# frame_left.pack(side=tk.LEFT,fill=tk.Y,padx=1,pady=1)
# frame_right=tk.Frame(frame1)
# tk.Label(frame_right,text="右侧标签1",bg="gray",width=10,height=5).grid(row=0,column=1)
# tk.Label(frame_right,text="右侧标签2",bg="pink",width=10,height=5).grid(row=1,column=0)
# tk.Label(frame_right,text="右侧标签3",bg="red",width=10,height=5).grid(row=1,column=1)
# frame_right.pack(side=tk.RIGHT)
# win.mainloop()

import tkinter as tk
from tkinter import Button

win = tk.Tk()
win.title("colov11")
win.geometry("600x600")

# 为每一行设置权重，使行在垂直方向均匀分配空间
for i in range(36):
    win.rowconfigure(i, weight=1)
# 为每一列设置权重，使列在水平方向均匀分配空间
for j in range(36):
    win.columnconfigure(j, weight=1)

# 全局计数器
click_count = 0

# 存储所有按钮的列表
buttons = []

# 定义按钮点击事件处理函数
def button_click():
    global click_count
    # 增加点击次数
    click_count += 1
    
    # 根据点击次数设置所有按钮颜色
    color = "black" if click_count % 2 == 1 else "red"
    # 遍历二维列表中的所有按钮
    for row in buttons:
        for btn in row:
            btn.config(bg=color)

# 创建按钮网格
for i in range(36):
    row_buttons = []
    for j in range(36):
        # 创建按钮并绑定点击事件
        btn = Button(win, width=1, height=1, command=button_click)
        btn.grid(row=i, column=j, sticky="nsew")
        row_buttons.append(btn)
    buttons.append(row_buttons)

win.mainloop()